package com.hexiang.rocketmq.controller;

import com.hexiang.rocketmq.producer.*;
import com.hexiang.rocketmq.producer.transaction.DemoTransactionMQProducer;
import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.remoting.exception.RemotingException;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;

@RestController
@RequestMapping("rocketmq")
public class RocketMQController {

    @Resource
    private DemoMQProducer demoMQProducer;

    @Resource
    private DemoTransactionMQProducer demoTransactionMQProducer;

    @Resource
    private OrderMQProducer orderMQProducer;

    @Resource
    private DelayTimeMessageProducer delayTimeMessageProducer;

    @Resource
    private SimpleBatchMessageMQProducer simpleBatchMessageMQProducer;

    @Resource
    private ComplexBatchMessageMQProducer complexBatchMessageMQProducer;

    @Resource
    private TagFilterProducer tagFilterProducer;

    @Resource
    private SqlFilterProducer sqlFilterProducer;

    @Resource
    private MessageFilterProducer messageFilterProducer;

//    @Resource
//    private OMSProducer omsProducer;

    @Resource
    private RpcProducer rpcProducer;

    @Resource
    private TraceMQProducer traceMQProducer;

    @RequestMapping("/send/{msg}")
    public String send(@PathVariable String msg) throws InterruptedException, RemotingException, MQClientException, MQBrokerException, UnsupportedEncodingException {
        demoMQProducer.sendMsg(msg);
        return "ok";
    }

    @RequestMapping("/sendAsyncMsg/{msg}")
    public String sendAsyncMsg(@PathVariable String msg) throws InterruptedException, RemotingException, MQClientException, UnsupportedEncodingException {
        demoMQProducer.sendAsyncMsg(msg);
        return "ok";
    }

    @RequestMapping("/sendOneway/{msg}")
    public String sendOneway(@PathVariable String msg) throws InterruptedException, RemotingException, MQClientException, UnsupportedEncodingException {
        demoMQProducer.sendOneway(msg);
        return "ok";
    }

    @RequestMapping("/sendWithTrace/{msg}")
    public String sendWithTrace(@PathVariable String msg) throws InterruptedException, RemotingException, MQClientException, MQBrokerException, UnsupportedEncodingException {
        traceMQProducer.sendMsg(msg);
        return "ok";
    }

    @RequestMapping("/sendTransactionMsg/{msg}")
    public String sendTransactionMsg(@PathVariable String msg) {
        demoTransactionMQProducer.sendTransactionMsg(msg);
        return "ok";
    }

    @RequestMapping("/sendOrderMsg")
    public String sendOrderMsg() throws MQClientException, InterruptedException, RemotingException, MQBrokerException {
        orderMQProducer.sendOrderMsg();
        return "ok";
    }

    @RequestMapping("/asyncSendOrderMsg")
    public String asyncSendOrderMsg() throws MQClientException, InterruptedException, RemotingException, MQBrokerException {
        orderMQProducer.asyncSendOrderMsg();
        return "ok";
    }

    @RequestMapping("/sendOneOrderMsg")
    public String sendOneOrderMsg() throws MQClientException, InterruptedException, RemotingException, MQBrokerException {
        orderMQProducer.sendOneOrderMsg();
        return "ok";
    }

    @RequestMapping("/sendBatchMsg")
    public String sendBatchMsg() {
        simpleBatchMessageMQProducer.sendBatchMsg();
        return "ok";
    }

    @RequestMapping("/sendComplexBatchMsg")
    public String sendComplexBatchMsg() {
        complexBatchMessageMQProducer.sendComplexBatchMsg();
        return "ok";
    }

    @RequestMapping("/sendDelayTimeMsg/{msg}")
    public String sendDelayTimeMsg(@PathVariable String msg) {
        delayTimeMessageProducer.sendDelayTimeMsg(msg);
        return "ok";
    }

    @RequestMapping("/sendMsgByTag")
    public String sendMsgByTag() {
        tagFilterProducer.sendMsgByTag();
        return "ok";
    }

    @RequestMapping("/sendMsgBySql")
    public String sendMsgBySql() {
        sqlFilterProducer.sendMsgBySql();
        return "ok";
    }

    @RequestMapping("/messageFilterProducer")
    public String messageFilterProducer() {
        messageFilterProducer.sendMsgByMessageFilter();
        return "ok";
    }

//    @RequestMapping("/sendOmsSyncMsg/{msg}")
//    public String sendSyncMsg(@PathVariable String msg) {
//        omsProducer.sendSyncMsg(msg);
//        return "ok";
//    }
//
//    @RequestMapping("/sendOmsOnewayMsg/{msg}")
//    public String sendOmsOnewayMsg(@PathVariable String msg) {
//        omsProducer.sendOnewayMsg(msg);
//        return "ok";
//    }
//
//    @RequestMapping("/sendOmsAsyncMsg/{msg}")
//    public String sendOmsAsyncMsg(@PathVariable String msg) {
//        omsProducer.sendAsyncMsg(msg);
//        return "ok";
//    }

    @RequestMapping("/syncSendRpcMsg/{msg}")
    public String syncSendRpcMsg(@PathVariable String msg) {
        rpcProducer.syncSendRpcMsg(msg);
        return "ok";
    }

    @RequestMapping("/asyncSendRpcMsg/{msg}")
    public String asyncSendRpcMsg(@PathVariable String msg) {
        rpcProducer.asyncSendRpcMsg(msg);
        return "ok";
    }

}
